<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>snmp-config-add</title>
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/form.jsp"%>
	
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery/jquery-ui.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/select/jquery.multiselect.min.js"></script>
	<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/style/default/select/jquery.multiselect.css" />
	<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/style/default/jqueryui/jquery-ui.css" />
	
	
  <script type="text/javascript">
  
  function add(){
	  //提交
	 $.ajax({
		   type: "POST", 
		   url: "${pageContext.request.contextPath}/config/snmp-config!save.action", //请求的action
		   data: $("#myform").serialize(), //传的参数
		   dataType: 'json',
		   success: function(data){ //结果
			   if(data == true){
				   var pWin = getTopWin(window).currentWin["add-snmp-config"];
				   pWin.datagrid();
				
				   getTopWin(window).closejBox("add-snmp-config");
			   }
			   
		   }
	});
  }
  
  $(function(){
	  $.formValidator.initConfig({formid:"myform"
          ,onerror:function(msg){}
          ,onsuccess:function(){
        	  		add();
          			return false;
          }
          });
	  
	  $("#ip").formValidator({onshow:"唯一且格式要正确",onfocus:"唯一且格式要正确",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"不能为空"})
	  .functionValidator({
			    fun:function(val,elem){
			    	var reg = /^([0-9]|[1-9][0-9]|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9][0-9]|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9][0-9]|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9][0-9]|1\d\d|2[0-4]\d|25[0-5])$/;
			    	if(val.match(reg) == null){
			    		return "格式不正确"
			        }
			        return true;
				}
	  })
	  .ajaxValidator({
			type : "post",
			async : false,
			url:'${pageContext.request.contextPath}/config/snmp-config!checkIp.action',
			data: "ip="+$("#ip").val(),
			datatype : "json",
			success : function(data){
				if(data== true)
				{
					return true;
				}else
				{
					return false;
				}
   			},
		buttons: $("#button"),
		error: function(){alert("服务器没有返回数据，可能服务器忙，请重试");},
		onerror : "已经存在",
		onwait : "正在校验"
		});
	  $("#port").formValidator({onshow:"请输入数字 长度(1-5)",onfocus:"请输入数字 长度(1-5)",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"不能为空"}).inputValidator({min:1,max:5,onerror:"长度范围(1-5)"})
	  .functionValidator({
			    fun:function(val,elem){
			    	 var reg = /^[0-9]+$/;
			    	    if(!reg.test(val)){
			    	        return "格式不正确";
			    	    }
			    	    return true;
				}
	  });
	  $("#userName").formValidator({onshow:"请输入读团体名",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"不能为空"});
	  $("#pwd").formValidator({onshow:"请输入写团体名",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"不能为空"});;
  });
  
  
  function closewin(){
	   getTopWin(window).closejBox("add-snmp-config");
  }

  
  </script>
  </head>
  
  <body class="padding-8">
    	<form action="" id="myform" name="myform" method="post">
    		<table class="table_eidt">
    			<tr>
	    			<td class="td_left" width="80px"><span class="span_alert">*</span>设备IP</td>
	    			<td class="td_right"><input type="text" name="ip" id="ip" class="input_text">
	    			<span id="ipTip" style="width:150px"></span></td>
    			</tr>
    			<tr>
	    			<td  class="td_left"><span class="span_alert">*</span>协议版本</td>
	    			<td class="td_right"><select name="protocol" id="protocol" style="width: 225px">
			          <option value="v1">v1</option>
			          <option value="v2c">v2c</option>
			          <option value="v3">v3</option>
			        </select>
	    			<span id="protocolTip" style="width:150px"></span></td>
    			</tr>
    			<tr>
	    			<td class="td_left"><span class="span_alert">*</span>端口</td>
	    			<td class="td_right"><input type="text" name="port" id="port" value="161" class="input_text">
	    			<span id="portTip" style="width:150px"></span></td>
    			</tr>
    			<tr>
	    			<td class="td_left"><span class="span_alert">*</span>读团体名</td>
	    			<td class="td_right"><input type="text" name="userName" id="userName" value="public" class="input_text">
	    			<span id="userNameTip" style="width:150px"></span></td>
    			</tr>
    			<tr>
	    			<td class="td_left"><span class="span_alert">*</span>写团体名</td>
	    			<td class="td_right"><input type="text" name="pwd" id="pwd" value="public" class="input_text">
	    			<span id="pwdTip" style="width:150px"></span></td>
    			</tr>
    		</table>
    		<div align="center" style="margin-top:9px;">
	    		<input type="submit" id="button" name="button" value="保存" class="btn-4">
	    		<input type="reset" class="btn-4">
	    		<input type="button" value="取消" onclick="closewin();" class="btn-4">
    		</div>
    	</form>
  </body>
</html>
